package org.graduates.webapp.actions.course.json;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.Course;
import org.projects.graduates.domain.Repeat;
import org.projects.graduates.domain.Teaching;
import org.projects.graduates.domain.TimeTable;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 获取课程的重复
 * @author Administrator
 *
 */
@ParentPackage("web")
public class GetTeachingDatesAction extends BaseAction {
	private static final long serialVersionUID = -8329739504778923798L;

	private List<TimeTable> times = new ArrayList<TimeTable>();

	private Repeat repeat;

	private long courseId = 0L;

	@Action(results = { @Result(name = "success", type = "json", params = {
			"includeProperties",
			"times\\[\\d+\\]\\.id, times\\[\\d+\\]\\.course, times\\[\\d+\\]\\.course.id," + "times\\[\\d+\\]\\.course.name, times\\[\\d+\\]\\.teachDate"
			 + ",repeat,repeat.summary,repeat.nullContent, repeat.teachDate " }) })
	public String execute() {

		if (0L != courseId) {
			for (TimeTable tt : TimeTable.findBy(courseId)) {
				times.add(tt);
			}
			
			Teaching tt = Teaching.findBy(Course.get(Course.class, courseId));
			
			if(null != tt){
				repeat = tt.getRepeat();
			}

		}

		return ActionSupport.SUCCESS;
	}

	public List<TimeTable> getTimes() {
		return times;
	}

	public void setTimes(List<TimeTable> times) {
		this.times = times;
	}

	public long getCourseId() {
		return courseId;
	}

	public void setCourseId(long courseId) {
		this.courseId = courseId;
	}

	public Repeat getRepeat() {
		return repeat;
	}

	public void setRepeat(Repeat repeat) {
		this.repeat = repeat;
	}

}
